# project
cmake_minimum_required(VERSION 2.8)
project (GCGE)
set(GCGE_VERSION_MAJOR 1)
set(GCGE_VERSION_MINOR 0)

# build type (set defualt type: RelWithDebInfo)
if(NOT CMAKE_BUILD_TYPE)
  message("Setting build type to 'RelWithDebInfo' as none was specified.")
  set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
    "MinSizeRel" "RelWithDebInfo")
endif()

# include
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/config/)
include(MPIconfig)

# src
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/app SRC_APP)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS)

# petsc
include_directories($ENV{PETSC_DIR}/include)
include_directories($ENV{PETSC_DIR}/include/petsc/private)
link_directories($ENV{PETSC_DIR}/lib)

# slepc
include_directories($ENV{SLEPC_DIR}/include)
include_directories($ENV{SLEPC_DIR}/include/slepc/private)
link_directories($ENV{SLEPC_DIR}/lib)

link_directories(/soft/apps/intel/oneapi_base_2021/mkl/2021.1.1/lib/intel64)

# this project
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)


# shared library
add_library(GCGE SHARED
    ${SRC_APP}
    ${SRCS}
)


target_link_libraries(GCGE
    PUBLIC
        petsc
        slepc
        metis
        parmetis
        mpi
        mkl_intel_lp64
        mkl_intel_thread
        mkl_core
        mkl_scalapack_lp64
        mkl_lapack95_lp64
        mkl_blas95_lp64
        pthread
        m
)

set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/shared/lib)
set(INCLUDE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/shared/include)
file(GLOB_RECURSE HEADER_ALL
    ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h
)
file(COPY ${HEADER_ALL} DESTINATION ${INCLUDE_OUTPUT_PATH})

# test
# add_executable(test ${CMAKE_CURRENT_SOURCE_DIR}/test/test_app_slepc.c)
# target_link_libraries(test 
#     PRIVATE 
#         GCGE
# )
# add_executable(test_s ${CMAKE_CURRENT_SOURCE_DIR}/test/test_app_slepc_s.c)
# target_link_libraries(test_s 
#     PRIVATE 
#         GCGE
# )
# add_executable(test_g ${CMAKE_CURRENT_SOURCE_DIR}/test/test_app_slepc_g.c)
# target_link_libraries(test_g 
#     PRIVATE 
#         GCGE
# )
# add_executable(test_ks_g ${CMAKE_CURRENT_SOURCE_DIR}/test/test_eps_ks_g.c)
# target_link_libraries(test_ks_g
#     PRIVATE 
#         GCGE
# )
# add_executable(test_bpcg ${CMAKE_CURRENT_SOURCE_DIR}/test/test_bpcg.c)
# target_link_libraries(test_bpcg 
#     PRIVATE 
#         GCGE
# )
add_executable(interface_s ${CMAKE_CURRENT_SOURCE_DIR}/test/interface_slepc_s.c)
target_link_libraries(test_s 
    PRIVATE 
        GCGE
)
add_executable(interface_g ${CMAKE_CURRENT_SOURCE_DIR}/test/interface_slepc_g.c)
target_link_libraries(test_g 
    PRIVATE 
        GCGE
)